<template>
  <div class="xtx-skeleton shan" v-for="i in 4" :key="i">
    <div class="container">
      <!-- 1 盒子-->
      <div class="block" :style="{backgroundColor:bg}"></div>
      <!-- 2 闪效果 xtx-skeleton 伪元素 --->
      <div class="right">
        <li v-for="i in 8" :key="i">
          <div class="pic" :style="{backgroundColor:bg}"></div>
          <p class="name" :style="{backgroundColor:bg}"></p>
          <p class="desc" :style="{backgroundColor:bg}"></p>
          <p class="price" :style="{backgroundColor:bg}"></p>
        </li>
      </div>
    </div>
  </div>

</template>
<script>
export default {
  name: 'XtxSkeleton',
  props: {
    width: { type: String, default: '100px' },
    height: { type: String, default: '100px' },
    bg: { type: String, default: '#ccc' }
  }
}
</script>
<style scoped lang="less">
.xtx-skeleton {
  display: inline-block;
  position: relative;
  width: 100%;
  overflow: hidden;
  vertical-align: middle;

  .container {
    margin-top: 115px;
  }

  .block {
    width: 240px;
    height: 610px;
    border-radius: 2px;
  }
  .right {
    position: absolute;
    top: 0;
    left: 0;
    width: 1000px;
    height: 610px;
    margin-left: 240px;
    z-index: 100;

    li {
      float: left;
      width: 240px;
      height: 300px;
      margin-left: 10px;
      margin-bottom: 10px;
      list-style: none;
      border-radius: 2px;
      &:nth-last-child(-n + 4) {
        margin-bottom: 0;
      }
      .pic {
        width: 180px;
        height: 160px;
        margin-left: 30px;
        border-radius: 2px;
      }
      .name {
        width: 180px;
        height: 50px;
        margin: 5px 0 0 30px;

        border-radius: 2px;
      }
      .desc {
        width: 180px;
        height: 35px;
        margin: 5px 0 5px 30px;
        border-radius: 2px;
      }
      .price {
        width: 180px;
        height: 40px;
        margin-left: 30px;

        border-radius: 2px;
      }
    }
  }
}
.shan {
  &::after {
    content: "";
    position: absolute;
    animation: shan 1.5s ease 0s infinite;
    top: 0;
    margin: 0 auto;
    width: 1240px;
    height: 100%;
    background: linear-gradient(
      to left,
      rgba(255, 255, 255, 0) 0,
      rgba(255, 255, 255, 0.3) 50%,
      rgba(255, 255, 255, 0) 100%
    );
    transform: skewX(-45deg);
  }
}
@keyframes shan {
  0% {
    left: -100%;
  }
  100% {
    left: 120%;
  }
}
</style>
